<?php
include_once "checksession.php"; 
include_once "db.php";

//See if the CALLID was inserted into the database via phonecall.php or something else
$q = mysql_query("SELECT Calls.cont_type FROM Calls WHERE Calls.Call_ID='" . $_GET[callid] . "'");
$qa = mysql_fetch_array($q);
$contact_type = $qa[cont_type];		
if (is_numeric($_GET[callid])){
 $calls ="SELECT DISTINCT problem_type.PT_desc, computer_type.CT_desc, browser_type.BT_desc, operating_system.os_desc, Calls.*
    FROM 
    problem_type, computer_type, browser_type, operating_system, Calls
	WHERE 
	Calls.Call_ID='$_GET[callid]' AND problem_type.PT_ID = Calls.problem_type ";
 $call = mysql_query($calls);
        $callsrez2 = mysql_fetch_array($call) ; 
        
		if ($callsrez2[os_type] != "0"){ 
		$calls .=  " AND computer_type.CT_ID = Calls.computer_type AND browser_type.BT_ID = Calls.browser_type AND operating_system.os_id = Calls.os_type";
		$call = mysql_query($calls);
		}
		 $callsrez = mysql_fetch_array($call) ; 
		$firstname = $callsrez[first_name];
		$lastname = $callsrez[last_name];
		$othername = $callsrez[other_name];
		$othername = $callsrez[other_name];
		$pipelineuserid = $callsrez[pipeline_userid];
        //$pipeline_reset = $callsrez[pipeline_reset];
		$dayphone = $callsrez[day_phone];
		$email = $callsrez[email];
		$KNum = $callsrez[KNum];
		$minitial = $callsrez[m_initial];
		$PTdesc = $callsrez[PT_desc];
		$CTdesc = $callsrez[CT_desc];
		$BTdesc = $callsrez[BT_desc];
		$OSdesc = $callsrez[os_desc];
		$section = $callsrez[course];
		$leftmssg = $callsrez[left_mssg];
		$problemdesc = $callsrez[problem_desc];
		$requestdate = $callsrez[request_date];
		$callclosed = $callsrez[call_closed];
		$higherlevel = $callsrez[higher_level];
		$oia_followup = $callsrez[oia_followup];
		$hl_followup = $callsrez[hl_followup];
		$semester = $callsrez[semester];
		$pending = $callsrez[pending];
		$bdate = $callsrez[birthdate];
		$course = $callsrez[course];
	}	
		
$resnotes = mysql_query("SELECT DISTINCT resolution_notes.note_desc, resolution_notes.note_date, resolution_notes.contact_type, resolution_notes.vista_reset, resolution_notes.pipeline_reset, resolution_notes.transfer_to, helpdesk_users.username, helpdesk_users.email as HDemail 
FROM 
resolution_notes, helpdesk_users 
WHERE 
resolution_notes.call_ID = '$_GET[callid]' AND helpdesk_users.HD_user_ID = resolution_notes.HD_user_ID ORDER BY resolution_notes.note_date");


while($row = mysql_fetch_array($resnotes, MYSQL_BOTH)) {

        $notedesc[] = $row[note_desc];
        $noteuser[] = $row[username];
        $notedate[] = $row[note_date];	
		$notetype[] = $row[contact_type];	
		$notetransfer[] = $row[transfer_to];
		$notevista[] = $row[vista_reset];
		$notepipeline[] = $row[pipeline_reset];

}

//if ( $section != "" ) {
//	$course_info = mysql_query("select * from current_courses WHERE section = '$section'") ;
//	$courseinfo = mysql_fetch_array($course_info) ;
 //   $coursenumber = $courseinfo[course_number];
 //   $coursesection = $courseinfo[section];
 //   $coursetitle = $courseinfo[course_title];	
//	$coursesemester = $courseinfo[semester];	
//} else {
 //   $coursenumber = "-";
 //   $coursesection = "-";
//    $coursetitle = "-";	
//	$coursesemester = "-";		

//}
?>
<html>
<head>
<title>Administrative Student Tracking Database</title>
<link href="meta-style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
</head>
<body>

<?php
include_once "topnav.php";

?>

  
  <table width="900" border="1" cellpadding="3" cellspacing="0" align="center" bordercolor="#666666">
   <tr align="right" valign="bottom" >
      <td colspan="2" align="left"><strong>
        <?php    
 echo "(<a href=edit_calls_detail.php?callid=" . $_GET[callid] .">Edit Call Info</a>)"
	  ?>
      </strong><?php if (is_numeric($_GET[callid]) && $contact_type == 'phone') {
	echo "This ticket was created by The Help Desk<br>";
	
/*
	$calls = mysql_query("SELECT DISTINCT problem_type.PT_desc, Calls.* 
    FROM 
    problem_type, Calls
	WHERE 
	Calls.Call_ID='$_GET[callid]' AND problem_type.PT_ID = Calls.problem_type");
	
         $callsrez = mysql_fetch_array($calls) ; 
		$firstname = $callsrez[first_name];
		$lastname = $callsrez[last_name];
		$othername = $callsrez[other_name];
		$pipelineuserid = $callsrez[pipeline_userid];
		$KNum = $callsrez[KNum];
        //$pipeline_reset = $callsrez[pipeline_reset];
		$dayphone = $callsrez[day_phone];
		$email = $callsrez[email];
		$minitial = $callsrez[m_initial];
		$PTdesc = $callsrez[PT_desc];
		$CTdesc = $callsrez[CT_desc];
		$BTdesc = $callsrez[BT_desc];
		$OSdesc = $callsrez[os_desc];
		$section = $callsrez[course];
		$leftmssg = $callsrez[left_mssg];
		$problemdesc = $callsrez[problem_desc];
		$requestdate = $callsrez[request_date];
		$callclosed = $callsrez[call_closed];
		$higherlevel = $callsrez[higher_level];
		$oia_followup = $callsrez[oia_followup];
		$hl_followup = $callsrez[hl_followup];
		$semester = $callsrez[semester];
		$pending = $callsrez[pending];
		$bdate = $callsrez[birthdate];
		$course = $callsrez[course];
	*/
		} ?> </td>
     <td colspan="2" align="left"><strong>&nbsp;
	  <?php   
	  if  ($higherlevel==1)
	  echo "<font color=red>THIS IS A HIGH LEVEL SUPPORT ENTRY</font>";
	  ?></strong></td>
    </tr>
    <tr align="right" valign="bottom" bgcolor="#006699">
      <td colspan="4" align="left"><font color=white><strong>CALL INFORMATION: # <?php echo $_GET[callid]; ?>  </strong></font></td>
    </tr>
    <tr align="right" valign="bottom">
      <td width="125" valign="bottom" bgcolor="#999999"><strong>First Name:</strong></td>
      <td width="359" align="left">
	  <?php
		 echo $firstname;
	    ?>&nbsp;</td>
      <td width="136" align="right" bgcolor="#999999"><strong>Date Timestamp:</strong></td>
      <td width="246" align="left"><?php
	  $date = substr($requestdate,5,2)."/".substr($requestdate,8,2)."/".substr($requestdate,0,4)." -".substr($requestdate,10,6);
	  
	   echo $date;
	  ?></td>
    </tr>
    <tr align="right" valign="bottom">
      <td width="125" valign="bottom" bgcolor="#999999"><strong>Middle Initial:</strong></td>
      <td width="359" align="left">
	  <?php
		 echo $minitial;
	    ?>&nbsp;</td>
      <td align="right" bgcolor="#999999"><strong>Left Voice Message?:</strong></td>
      <td width="246" align="left"><?php
	  if ($leftmssg==1)
	   echo "Yes";
	  else
		echo "No";
  ?></td>
    </tr>
    
      <tr align="right" valign="bottom">
      <td valign="bottom" bgcolor="#999999"><strong>Last Name:</strong></td>
      <td align="left"><?php
	  echo $lastname;
	  ?>&nbsp;</td>
      <td align="right" bgcolor="#999999"><strong>Computer Type:</strong></td>
      <td align="left"><?php if ($callsrez[computer_type] != 0) 
	  echo $CTdesc;
	  else 
	  echo "<em>-not specified-</em>";
	  ?></td>
    </tr>
    <tr align="right" valign="bottom">
      <td valign="bottom" bgcolor="#999999"><strong>Other Name(s):</strong></td>
      <td align="left"><?php
	  echo $othername;
	  ?>&nbsp;</td>
      <td align="right" bgcolor="#999999"><strong>Browser Type:</strong></td>
      <td align="left"><?php if ($callsrez[browser_type] != 0)
	  echo $BTdesc;
	  else
	  echo "<em>-not specified-</em>";
	  ?></td>
    </tr>
    <tr align="right" valign="bottom">
      <td valign="bottom" bgcolor="#999999"><strong>Date of Birth:</strong></td>
      <td align="left"><?php if ($bdate != "")
	  echo $bdate;
	  else
	  echo "<em>-not specified-</em>";
	  ?></td>
      <td align="right" bgcolor="#999999"><strong>Operating System:</strong></td>
      <td align="left"><?php if ($callsrez[os_type] != 0)
	  echo $OSdesc;
	  else
	  echo "<em>-not specified-</em>"
	  ?></td>
    </tr>
    <tr align="right" valign="bottom">
      <td width="125" valign="bottom" bgcolor="#999999"><strong>Pipeline username:</strong></td>
      <td align="left"><?php
	  echo $pipelineuserid;
	  ?>        &nbsp;</td>
      <td align="right" bgcolor="#999999"><strong>Semester:</strong></td>
      <td align="left"><?php
	  if ($semester != "")
	  echo $semester;
	  else 
	  echo "<em>-not specified-</em>";
	  ?></td>
    </tr>
    <tr align="right" valign="bottom">
      <td width="125" valign="bottom" bgcolor="#999999"><strong>Student ID (K#):</strong></td>
      <td align="left"><?php if ($KNum != "")
	  echo $KNum;
	  else
	  echo "<em>-not specified-</em>";
	  ?> </td>
      <td align="right" bgcolor="#999999"><strong>Course:</strong></td>
      <td align="left"><?php if ($course != "")
	  echo $course;
	  else
	  echo "<em>-not specified-</em>"
	  ?></td>
    </tr>
    <tr align="right" valign="bottom">
      <td width="125" valign="bottom" bgcolor="#999999"><strong>Phone:</strong></td>
      <td align="left"><?php if ($dayphone != "")
	  echo $dayphone;
	  else
	  echo "<em>-not specified-</em>"
	  ?></td>
      <td align="right" bgcolor="#999999">&nbsp;</td>
      <td align="left"> <FORM action="searchcalls.php" METHOD="POST"><input name="startMonth" type="hidden" value="%%"> <input name="endMonth" type="hidden" value="%%"><input name="post" type="hidden" value="1"><input name="KNum" id="KNum" type="hidden" value="<?php echo $KNum ?>">
       <input type=SUBMIT value="Search K Number" name="SUBMIT"></FORM></td>
    </tr>
    <tr align="right" valign="bottom">
      <td valign="bottom" bgcolor="#999999"><strong>Email:</strong></td>
      <td align="left"><?php
	  echo "<a href=mailto:".$email.">" .$email. "</a>" ;
	  ?></td>
      <td align="right" bgcolor="#999999">&nbsp;</td>
      <td align="left">&nbsp;</td>
    </tr>
    <tr align="right" valign="bottom">
      <td valign="bottom" bgcolor="#999999"><strong>Problem Type:</strong></td>
      <td align="left"><span style="font-weight:bold"><?php
	  echo $PTdesc;
	  ?></span></td>
      <td align="right" bgcolor="#999999">&nbsp;</td>
      <td align="left">&nbsp;</td>
    </tr>
    <tr>
      <td width="125" align="right" valign="middle" bgcolor="#999999"><strong>Problem Description:</strong></td>
      <td colspan="3"><?php
	  echo nl2br($problemdesc);
	  ?>        &nbsp;</td>
    </tr>
</table>
<br>
	<table width="900" border="1" cellpadding="3" cellspacing="0" bordercolor="#666666" align="center">
    <tr align="left" bgcolor="#006699">
      <td colspan="6"><font color=white><strong>CALL HISTORY </strong></font></td>
    </tr>
    <tr  align="left" bgcolor="#999999">
      <td width="122"><strong>Date/Time of ticket:</strong></td>
      <td width="444"><strong>Description/Notes:</strong></td>
      <td width="98"><strong>Type of contact:</strong></td>
      <td width="96"><strong>Transfered to?:</strong></td>
      
  <!--<td width="58"><strong>Vista Reset?</strong></td> -->
  <!--<td width="57"><strong>Pipeline Reset?</strong></td> -->
      <td width="98"><strong>Helpdesk User:</strong></td>
    </tr>
    
 	  <? 

		$num = count($noteuser);
		for($i=0; $i<$num ;$i++) {
			if ($notetype[$i] == "comment") {
				echo "<tr align=left bgcolor='#FFFBC9'> \n";
			}
			else if ($notetype[$i] == "student-reply") {
				echo "<tr align=left bgcolor='#f5f2e0'> \n";
			}
			else if ($notetransfer[$i] == "admissions" || $notetransfer[$i] == "counseling" || $notetransfer[$i] == "other_transfer" || 					 $notetransfer[$i] == "admissions sup" || $notetransfer[$i] == "faculty Staff HD" || $notetransfer[$i] == "cashiers" || $notetransfer[$i] == "financial aid") {
				echo "<tr align=left bgcolor='#6db2f2'> \n";
			}
			else {
				echo  "<tr align=left> \n";
			}
			$cdate = substr($notedate[$i],5,2)."/".substr($notedate[$i],8,2)."/".substr($notedate[$i],0,4). "-" .substr($notedate[$i],10,6);
			echo "<td align=right>" . $cdate . "&nbsp;</td> \n";
			echo "<td align=left>" . nl2br($notedesc[$i]) . "&nbsp;</td> \n";
			echo "<td align=center>" . $notetype[$i] . "&nbsp;</td> \n";
			echo "<td align=center>" . $notetransfer[$i] . "&nbsp;</td> \n";
			//if ($notevista[$i]==1)
			//echo "<td align=right>Yes</td> \n";
			//else if ($notevista[$i]==2)
			//echo "<td align=right>No</td> \n";
			// else 
			// echo "<td align=right>?</td> \n";
			
			//if ($notepipeline[$i]==1)
			//	echo "<td align=center>Yes</td> \n";
			//else if ($notepipeline[$i]==2)
			//	echo "<td align=center>No</td> \n";
			//else 
			//	echo "<td align=center>?</td> \n";
	 
			echo "<td align=center>" . $noteuser[$i] . "&nbsp;</td> \n";
			echo "</tr> \n";
	   }


		?>
</table>
	<br>
<form action="insert_note.php" method="POST">
	  <input type="hidden" name="CallID" value="<? echo $_GET[callid] ?>">
	  <input type="hidden" name="HDuserID" value="<? echo $_SESSION[ID] ?>">
  <table width="900" border="1" cellpadding="3" cellspacing="0" bordercolor="#666666" align="center">
    <tr>
      <td colspan="4" align="left" bgcolor="#006699"><font color=white><strong>ADD INFORMATION:</strong></font></td>
    </tr>
	<tr>
	<td colspan="4"><span class="style1">Please <b>DO NOT</b> leave ANY fields blank!</span></td>
	</tr>
    <tr>
      <td width="125" align="right" bgcolor="#999999"><strong>Resolution Notes:</strong></td>
      <td width="365"><textarea name="notes" cols="60" rows="6" wrap="physical"></textarea></td>
      <td width="132" align="right" bgcolor="#999999"><strong>Type:</strong> </td>
      <td width="244">
<table><tr>
        		<td width="167"><b>Transferred to:</b><br/>
        		  <select name="transfer_to">
                    <option value="">none</option>
                    <option value="admissions">Admissions</option>
                    <option value="admissions sup">Admissions Sup.</option>
                    <option value="counseling">Counseling</option>
                    <option value="cashiers">Cashiers</option>
                    <option value="financial aid">Financial Aid</option>
                    <option value="faculty Staff HD">Faculty Staff HD</option>
                    <option value="other">Other Ext.</option>
                  </select></td>
        <td width="115">
	  
<input type="checkbox" name="contact_type" value="email"> 
Email<br>
<input type="checkbox" name="contact_type" value="phone">
Phone<br>
<input type="checkbox" name="contact_type" value="in-person">
In-Person<br>
<input type="checkbox" name="contact_type" value="voicemail">
Voicemail<br>
<input type="checkbox" name="contact_type" value="comment"> 
Note<br>
<input type="checkbox" name="contact_type" value="student-reply"> 
Student<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reply
</td>

		</tr>
	</table>
    </tr>
    <tr>
	  <td width="125" align="right" bgcolor="#999999"><strong>Pipeline Reset?</strong></td>
      <td><input name="pipeline_reset" type="radio" value="1"> 
        Yes 
          <input name="pipeline_reset" type="radio" value="2">
        No</td>
      
    
      <td width="132" align="right" bgcolor="#999999"><strong>Call Closed?</strong></td>
      <td>
       <input name="closed" type="radio" value="2" <? if($callclosed == 2) echo "checked";?>> 
       Yes
        <input name="closed" type="radio" value="1" <? if($callclosed == 1) echo "checked";?>>
No</td></tr>
    <tr>
      <td width="125" align="right" bgcolor="#999999"><strong>High Level Support? </strong></td>
      <td align="left"><input name="high_level" type="radio" value="1"<? if($higherlevel == 1) echo "checked";?>>
Yes
  <input name="high_level" type="radio" value="2"<? if($higherlevel == 2) echo "checked";?>>
No</td>
      <td width="132" align="right" bgcolor="#999999"><strong> Supervisor Follow Up?</strong></td>
      <td align="left"><input name="hl_followup" type="radio" value="1"<? if($hl_followup == 1) echo "checked";?>>
Yes  
  <input name="hl_followup" type="radio" value="2"<? if($hl_followup == 2) echo "checked";?>>
No</td>
    </tr>
    <tr>
      <td width="125" align="right" bgcolor="#999999"><strong>Pending more info?</strong></td>
      <td align="left"><input name="pending" type="radio" value="1"<? if($pending == 1) echo "checked";?>>
Yes  
  <input name="pending" type="radio" value="2"<? if($pending == 2) echo "checked";?>>
No</td>
      <td width="132" align="right" bgcolor="#999999"><strong>Intern Follow Up? </strong></td>
      <td align="left"><input name="oia_followup" type="radio" value="1"<? if($oia_followup == 1) echo "checked";?>>
Yes
  <input name="oia_followup" type="radio" value="2"<? if($oia_followup == 2) echo "checked";?>>
No</td>
    </tr>
    <tr>
      <td colspan="4" align="right"><input type="submit" name="Submit" value="Submit"></td>
      </tr>
  </table>
</form>
<a href="index.php">Back to Main Menu</a>
</body>
</html>
